package com.virtualightning.app.ui.main

import android.os.Bundle
import android.view.*
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.virtualightning.app.databinding.TextViewHolderBinding
import com.virtualightning.app.entity.ProductBean
import com.virtualightning.mvvm.fragments.AsyncRecyclerViewFragment
import com.virtualightning.mvvm.impl.adapter.*

/**
 *  Anchor : Create by CimZzz
 *  Time : 2021/1/26 18:16:23
 *  Project : zxs-new
 *
 */
class SimpleListFragment : AsyncRecyclerViewFragment() {
	lateinit var viewModel: SimpleListViewModel

	override fun onActivityCreated(savedInstanceState: Bundle?) {
		super.onActivityCreated(savedInstanceState)
	}

	override fun onRefresh(adapterProxy: InitAdapterProxy) {

	}

	override fun getAdapterOptions(): UniverseAdapter.Options {
		return UniverseAdapter.Options(
			dataMatcherSet = setOf(
				UniverseAdapter.DataMatcher(ProductBean::class.java, TextViewHolder::class.java)
			),
			adapterLoadStrategy = DefaultAdapterLoadStrategy()
		)
	}

	override fun configRecyclerView(recyclerView: RecyclerView) {
		recyclerView.layoutManager =
			LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
	}
}


class TextViewHolder(
	itemView: View,
	private val textViewHolderBinding: TextViewHolderBinding
) : UniverseAdapter.BaseViewHolder<ProductBean>(itemView) {

	init {
		itemView.setOnClickListener {
			sendCommand(getData()?.title)
		}
	}

	override fun onBindData(data: ProductBean, helper: UniverseAdapter.ViewHolderHelper) {
		textViewHolderBinding.productBean2 = data
	}
}